/**
 *
 */
package com.naiterui.ehp.bs.doctor.controller;

import com.naiterui.ehp.bp.constants.SwaggerTag;
import com.naiterui.ehp.bp.support.exception.BusinessException;
import com.naiterui.ehp.bp.support.exception.PublicService;
import com.naiterui.ehp.bp.support.exception.ResponseVO;
import com.naiterui.ehp.bs.doctor.exception.ExceptionCodes;
import com.naiterui.ehp.bs.doctor.service.IHospitalService;
import com.naiterui.ehp.bs.doctor.vo.HospitalVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Api(tags = {SwaggerTag.DOCTOR + SwaggerTag.BASIC_INFO})
@RequestMapping("ad/hospital")
@Controller
public class AdHospitalController {

    private static final Logger LOGGER = LoggerFactory.getLogger(AdPatientGroupController.class);

    @Autowired
    private IHospitalService hospitalService;

    /**
     * <根据城市ID获取医院列表>
     * @param cityId
     * @return String <返回值描述>
     * @Throws 异常信息
     * @History 2015-6-21 上午11:10:29 by guoyongxiang
     */
    @ApiOperation(value = "根据城市ID获取医院列表", notes = "获取医院列表", httpMethod = "POST")
    @ApiImplicitParams({ @ApiImplicitParam(name = "cityId", value = "城市ID", required = true, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "name", value = "医院名称", required = true, dataType = "string", paramType = "query") })
    @RequestMapping("list")
    @ResponseBody
    public ResponseVO<List<HospitalVO>> getList(Integer cityId, String name, Integer max) throws BusinessException {
        List<HospitalVO> voList = null;
        if (StringUtils.isEmpty(cityId) && StringUtils.isEmpty(name)) {
            LOGGER.error("城市ID与医院名为空,cityId=" + cityId + ",name=" + name);
            throw new BusinessException(ExceptionCodes.PARAM_ERROR);
        }
        try {
            voList = this.hospitalService.getHopitalList(cityId, name, max);
        } catch (Exception e) {
            e.printStackTrace();
            LOGGER.error("获取医院列表异常,cityId=" + cityId);
            throw new BusinessException(ExceptionCodes.FAILED);
        }
        return PublicService.returnResponseVO(voList);
    }
}
